/*
 * @Author: 矫建武 1452239416@qq.com
 * @Date: 2024-09-04 17:13:38
 * @LastEditTime: 2025-02-17 12:47:38
 * @FilePath: \tool\vite.config.ts
 * @Description:
 *
 * @file: https://github.com/OBKoro1/koro1FileHeader/wiki/%E5%AE%89%E8%A3%85%E5%92%8C%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B
 */
import { fileURLToPath, URL } from 'node:url'
import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [
    vue(),
    visualizer({
      emitFile: false,
      filename: 'stats.html',
      open: true,
      sourcemap: true
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    host: '0.0.0.0',
    port: 1234, // 启动端口号
    open: true, // 启动后是否自动打开网页
    cors: true, // 允许跨域
    hmr: true, // 开启热更新
    proxy: {
      '/api': {
        target: 'http://localhost:1024',
        changeOrigin: true //是否允许跨域
      }
    }
  },
  build: {
    terserOptions: {
      // 生产环境移除console、debugger
      compress: {
        drop_console: true, // 默认false
        drop_debugger: true // 默认true
      }
    },
    rollupOptions: {
      external: ['jszip', 'JSZip']
    }
  }
})
